SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE FUNCTION dbo.[DnnProduct_GetSortSql]
(
	@SortBy nvarchar(100),
	@SortAscending BIT,
	@Default nvarchar(100)
)
RETURNS nvarchar(max)
AS
	BEGIN
		DECLARE @sortSql nvarchar(max)
		SET @sortSql = ''
		IF @SortBy = ''
			SET @SortBy = @Default
		SET @sortSql = N'ORDER BY [' + @SortBy + CASE WHEN @SortAscending = 1 THEN N'] ASC' ELSE N'] DESC' END
		
		RETURN(@sortSql)
	END	
GO
